package pattern.structural.flyweight;

import java.util.HashMap;
import java.util.Map;

public class FlyWeightFactory {

	private static Map<String,Flyweight> pool = new HashMap<String,Flyweight>();
	
	private FlyWeightFactory() {};
	
	public static Flyweight getFlyWeight(String intrinsicState) {
		Flyweight flyweight = pool.get(intrinsicState);
		if(flyweight == null) {
			flyweight = new ConcreteFlyweight(intrinsicState);
			pool.put(intrinsicState, flyweight);
		}
		return flyweight;
	}
}
